package gimys;

import gimys.SolidObject.Skin;
import gimys.Trigger.triggerType;

import java.util.ArrayList;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.SpriteSheet;

public class Level {

	/**
	 * The big dirty level loader
	 * @param numLevel
	 * @param pGameplayState
	 * @param container
	 * @return
	 * @throws SlickException
	 */
	static void loadLevel(int numLevel, GameplayState pGameplayState, GameContainer container) throws SlickException{
		Skin race;
		Path pDefaultPath;
		
		// Defaut pour tous les levels
		pGameplayState.afficheCollision = false;
		pGameplayState.afficheAttack = true;
		pGameplayState.afficheAgro = false;
		pGameplayState.triggers = new ArrayList<Trigger>() ;
		pGameplayState.lesDeco  = new ArrayList<Deco>() ;
		
		// definition des levels
		switch (numLevel) {
		case 0:
			pGameplayState.background = new SpriteSheet("data/map0.png", (int) pGameplayState.mapWidth, (int) pGameplayState.mapHeight);
			pGameplayState.maskCollider = new SpriteSheet("data/map0-nb.png", (int) pGameplayState.mapWidth, (int) pGameplayState.mapHeight);
			// instantiate solidObjects :)
			pGameplayState.solidObjects = new ArrayList<SolidObject>();
			// Key
			// ----------
			pGameplayState.key = new Key(new Point(230,1220)); // a changer
			pGameplayState.solidObjects.add(pGameplayState.key);
			// Door
			// ----------
			pGameplayState.door = new Door(new Point(364,45)); // a changer
			pGameplayState.solidObjects.add(pGameplayState.door);

			//Singe bas droite
			pDefaultPath = new Path(new Point(676,1420)); // coords de l'agent
			pDefaultPath.addPoint(new Point(770,1420));
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );
			
			//Singe bas droite 2
			pDefaultPath = new Path(new Point(696,1500)); // coords de l'agent
			pDefaultPath.addPoint(new Point(790,1500));
			pDefaultPath.addPoint(new Point(790,1500));
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );

			//Loup bas droite
			pDefaultPath = new Path(new Point(933,1221)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );

			//Loup milieu
			pDefaultPath = new Path(new Point(706,1012)); // coords de l'agent
			pDefaultPath.addPoint(new Point(588, 968));
			pDefaultPath.addPoint(new Point(286, 968));
			pDefaultPath.addPoint(new Point(588, 968));
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );
			
			//ane bas gauche 1
			pDefaultPath = new Path(new Point(90,1124)); // coords de l'agent
			pDefaultPath.addPoint(new Point(186, 1264));
			pDefaultPath.addPoint(new Point(300, 1264));
			pDefaultPath.addPoint(new Point(300, 1130));
			pDefaultPath.addPoint(new Point(300, 1310));
			pDefaultPath.addPoint(new Point(90, 1310));
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(120,1124), race, pDefaultPath) );
			
			//ane bas gauche 2
			pDefaultPath = new Path(new Point(330, 1264)); // coords de l'agent
			pDefaultPath.addPoint(new Point(300, 1130));
			pDefaultPath.addPoint(new Point(300, 1310));
			pDefaultPath.addPoint(new Point(90, 1310));
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );
			

			//Loup ligne 1
			pDefaultPath = new Path(new Point(547,799)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );
			
			//Loup 2 ligne 1
			pDefaultPath = new Path(new Point(547,826)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );


			//Serpent ligne 2
			pDefaultPath = new Path(new Point(547,664)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );
			
			//Serpent 2 ligne 2
			pDefaultPath = new Path(new Point(547,699)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );

			//Ane ligne 3
			pDefaultPath = new Path(new Point(547,564)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );
			
			//Ane ligne 3
			pDefaultPath = new Path(new Point(547,535)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );
			
			//Singe ligne 4
			pDefaultPath = new Path(new Point(547,420)); // coords de l'agent
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );
			
			//Singe ligne 4
			pDefaultPath = new Path(new Point(547,380)); // coords de l'agent
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );

			// Player
			pGameplayState.player = new Player(new Point(60,1500));
			pGameplayState.player.setSpeed(0.13f);
			pGameplayState.solidObjects.add(pGameplayState.player);
			pGameplayState.time=0;

			break;
		case 1:
			pGameplayState.background = new SpriteSheet("data/map1.png", (int) pGameplayState.mapWidth, (int) pGameplayState.mapHeight);
			pGameplayState.maskCollider = new SpriteSheet("data/map1-nb.png", (int) pGameplayState.mapWidth, (int) pGameplayState.mapHeight);
			// instantiate solidObjects :)
			pGameplayState.solidObjects = new ArrayList<SolidObject>();
			// Key
			// ----------
			pGameplayState.key = new Key(new Point(534,729)); // a changer
			pGameplayState.solidObjects.add(pGameplayState.key);
			// Door
			// ----------
			pGameplayState.door = new Door(new Point(498,1)); // a changer
			pGameplayState.solidObjects.add(pGameplayState.door);

			//Singe spawn trigger 1
			Point alarm = new Point(885,731);
			pDefaultPath = new Path(new Point(855, 700));
			race = Skin.MONKEY;
			pGameplayState.triggers.add(new Trigger(triggerType.EMBUSH, alarm, race, pDefaultPath, 5000, 1, new Point(885,789)));


			//Loup d�but
			pDefaultPath = new Path(new Point(390,1210));
			pDefaultPath.addPoint(new Point(190,1210)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(390,1210), race, pDefaultPath) );
			
			//Loup d�but
			pDefaultPath = new Path(new Point(390,1260));
			pDefaultPath.addPoint(new Point(190,1260)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(290,1260), race, pDefaultPath) );

			//Loup retour
			pDefaultPath = new Path(new Point(316,982)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(316,982), race, pDefaultPath) );
			
			//Loup haut gauche
			pDefaultPath = new Path(new Point(162,267)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(162,267), race, pDefaultPath) );



			//Serpent cl� 2
			pDefaultPath = new Path(new Point(486,769)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(new Point(486,769), race, pDefaultPath) );
			
			//Serpent cl� 3
			pDefaultPath = new Path(new Point(546,789)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(new Point(546,789), race, pDefaultPath) );

			//Serpent 1 porte sortie
			pDefaultPath = new Path(new Point(546,108)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );
			
			//Serpent 2 porte sortie
			pDefaultPath = new Path(new Point(516,108)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );
			
			//Serpent 3 porte sortie
			pDefaultPath = new Path(new Point(576,108)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(race, pDefaultPath) );

			//Ane 1 porte entr�e
			pDefaultPath = new Path(new Point(540,1365)); // coords de l'agent
			pDefaultPath.addPoint(new Point(220, 1365));
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(500,1365), race, pDefaultPath) );
			
			//Ane 2 porte entr�e
			pDefaultPath = new Path(new Point(560,1365)); // coords de l'agent
			pDefaultPath.addPoint(new Point(560, 1245));
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(560,1365), race, pDefaultPath) );

			//Ane avant baraquement 1
			pDefaultPath = new Path(new Point(705,972)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(705,972), race, pDefaultPath) );

			//Ane avant baraquement 2
			pDefaultPath = new Path(new Point(813,1011)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(813,1011), race, pDefaultPath) );

			//Ane avant baraquement 3
			pDefaultPath = new Path(new Point(790,960)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(790,960), race, pDefaultPath) );
			
			//Singe 1 barack
			pDefaultPath = new Path(new Point(750,400));
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(750,400), race, pDefaultPath) );
			
			//Ane garde haut 1
			pDefaultPath = new Path(new Point(618,273)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(618,273), race, pDefaultPath) );

			//Ane garde haut 2
			pDefaultPath = new Path(new Point(726,246)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(726,246), race, pDefaultPath) );

			pGameplayState.player = new Player(new Point(560,1500));
			pGameplayState.player.setSpeed(0.13f);
			pGameplayState.solidObjects.add(pGameplayState.player);
			pGameplayState.time=0;
			break;
			
		case 2:
			pGameplayState.background = new SpriteSheet("data/map-fin.png", (int) pGameplayState.mapWidth, (int) pGameplayState.mapHeight);
			pGameplayState.maskCollider = new SpriteSheet("data/map-fin-nb.png", (int) pGameplayState.mapWidth, (int) pGameplayState.mapHeight);
			// instantiate solidObjects :)
			pGameplayState.solidObjects = new ArrayList<SolidObject>();
			// Key
			// ----------
			pGameplayState.key = null;
			// Door
			// ----------
			pGameplayState.door = null;

			//Singe haut gauche 1
			pDefaultPath = new Path(new Point(168,898)); // coords de l'agent
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(168,898), race, pDefaultPath) );


			//Singe haut gauche 2
			pDefaultPath = new Path(new Point(236,898)); // coords de l'agent
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(236,898), race, pDefaultPath) );


			//Loup gardien cl� 1
			pDefaultPath = new Path(new Point(102,1450)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(102,1450), race, pDefaultPath) );


			//Loup gardien cl� 2
			pDefaultPath = new Path(new Point(90,1384)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(90,1384), race, pDefaultPath) );


			//Loup gardien cl� 3
			pDefaultPath = new Path(new Point(164,1362)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(164,1362), race, pDefaultPath) );


			//Loup gardien cl� 4
			pDefaultPath = new Path(new Point(210,1384)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(210,1384), race, pDefaultPath) );

			//Ane central
			pDefaultPath = new Path(new Point(515,1098)); // coords de l'agent
			race = Skin.DONKEY; 
			pGameplayState.solidObjects.add( new Animal(new Point(515,1098), race, pDefaultPath) );
			
			//Ane central 2
			pDefaultPath = new Path(new Point(485,1098)); // coords de l'agent
			race = Skin.DONKEY; 
			pGameplayState.solidObjects.add( new Animal(new Point(485,1098), race, pDefaultPath) );
			
			//Serpent droite 1
			pDefaultPath = new Path(new Point(892, 1136)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(new Point(892, 1136), race, pDefaultPath) );


			//Serpent droite 2
			pDefaultPath = new Path(new Point(894, 1190)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(new Point(894, 1190), race, pDefaultPath) );


			//Singe salle 1
			pDefaultPath = new Path(new Point(250,274)); // coords de l'agent
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(250,274), race, pDefaultPath) );


			//Singe salle 2
			pDefaultPath = new Path(new Point(345,274)); // coords de l'agent
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(345,274), race, pDefaultPath) );


			//Singe salle 3
			pDefaultPath = new Path(new Point(498,274)); // coords de l'agent
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(498,274), race, pDefaultPath) );


			//Singe salle 4
			pDefaultPath = new Path(new Point(646,274)); // coords de l'agent
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(646,274), race, pDefaultPath) );


			//Singe salle 5
			pDefaultPath = new Path(new Point(754,274)); // coords de l'agent
			race = Skin.MONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(754,274), race, pDefaultPath) );


			//Loup salle 1
			pDefaultPath = new Path(new Point(198,650)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(198,650), race, pDefaultPath) );


			//Loup salle 2
			pDefaultPath = new Path(new Point(780,650)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(780,650), race, pDefaultPath) );


			//Loup salle 3
			pDefaultPath = new Path(new Point(346,582)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(346,582), race, pDefaultPath) );


			//Loup salle 4
			pDefaultPath = new Path(new Point(674,582)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(674,582), race, pDefaultPath) );


			//Loup salle 5
			pDefaultPath = new Path(new Point(500,546)); // coords de l'agent
			race = Skin.WOLF;
			pGameplayState.solidObjects.add( new Animal(new Point(500,546), race, pDefaultPath) );


			//Serpent salle 1
			pDefaultPath = new Path(new Point(148,320)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(new Point(148,320), race, pDefaultPath) );


			//Serpent salle 2
			pDefaultPath = new Path(new Point(228,362)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(new Point(228,362), race, pDefaultPath) );


			//Serpent salle 3
			pDefaultPath = new Path(new Point(280,424)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(new Point(280,424), race, pDefaultPath) );


			//Serpent salle 4
			pDefaultPath = new Path(new Point(228,502)); // coords de l'agent
			race = Skin.SNAKE;
			pGameplayState.solidObjects.add( new Animal(new Point(228,502), race, pDefaultPath) );



			//Serpent salle 5
			pDefaultPath = new Path(new Point(148,592)); // coords de l'agent
			race = Skin.SNAKE; 
			pGameplayState.solidObjects.add( new Animal(new Point(148  ,592), race, pDefaultPath) );


			//Ane salle 1
			pDefaultPath = new Path(new Point(810,320)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(810,320), race, pDefaultPath) );


			//Ane salle 2
			pDefaultPath = new Path(new Point(750,362)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(750,362), race, pDefaultPath) );


			//Ane salle 3
			pDefaultPath = new Path(new Point(670,424)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(670,424), race, pDefaultPath) );


			//Ane salle 4
			pDefaultPath = new Path(new Point(750,502)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(750,502), race, pDefaultPath) );


			//Ane salle 5
			pDefaultPath = new Path(new Point(810,592)); // coords de l'agent
			race = Skin.DONKEY;
			pGameplayState.solidObjects.add( new Animal(new Point(810,592), race, pDefaultPath) );
			
			pGameplayState.solidObjects.add(new Prince(new Point(486,81)));

			pGameplayState.player = new Player(new Point(500,1500));
			pGameplayState.player.setSpeed(0.13f);
			pGameplayState.solidObjects.add(pGameplayState.player);
			pGameplayState.time=0;
			break;
		}

	}
}
